<style>
.label{cursor:pointer;}
ul.mylist{padding:0px;}
ul.mylist li{list-style-type:none;border:1px solid #ccc;padding:6px;margin:5px;text-align:center;float:left;cursor:pointer;border-radius:5px;}
ul.mylist li:hover{background-color:#eee;color:red;}
</style>
<div class="row">
<a href="{:U('Tag/index')}"><button type="button" class="btn btn-primary active">标签列表</button></a>
<button type="button" class="btn btn-primary"  data-toggle="modal" data-target="#myModal">添加标签</button>
<button type="button" class="btn btn-primary"  data-toggle="modal" data-target="#myModal2">采集标签</button>
</div>
<div class="row col-sm-12">
<ul class="mylist">
<volist id="data" name="data">
	<li class="tooltip-test tag"  data-toggle="tooltip" title="点击该标签将会删除" value="{$data.id}">{$data.name}</li>
</volist>
</ul>
</div>
{$page}




<!-- 模态框（Modal）手动添加标签 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
       
         <div class="modal-body">
         <form role="form" id="tag_form" method="post" action="{:U('Tag/addtag')}">
	         <div class="form-group col-sm-4">
	          <label for="pid">标签分类</label>
		      <select name="pid" id="pid" class="form-control">
		      	<option value="0">请选择标签分类</option>
		      	<volist id="type" name="type">
		         <option value="{$type.id}">{$type.name}</option>
		        </volist>
		      </select>
		      </div>
		      <div class="form-group col-sm-4" id="sonid_div" style="display:none;clear:right;margin-left:-30px;">
	          <label for="sonid">&nbsp;</label>
		      <select name="sonid" id="sonid" class="form-control"></select>
		      </div>
  			<div class="form-group col-sm-12">
    			<label for="content">添加标签</label>
    			<textarea id="content" name="content" class="form-control" rows="10" placeholder='火影忍者,西游记,金瓶梅'></textarea>
    			<span class="help-block">支持批量添加标签，多个标签请使用英文逗号分隔</span>
  			</div>
		</form>
         </div>
         <div class="modal-footer" style="clear:both">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
            <button type="button" id="submit_tag" class="btn btn-primary">马上添加标签</button>
         </div>
      </div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>


<!-- 模态框（Modal）自动采集百度风云榜标签 -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
       
         <div class="modal-body">
         <form role="form" id="collect_form_code" method="post" action="{:U('Tag/collect_baidu_tag')}">
         	<div class="form-group col-sm-4">
	          <label for="pid2">标签分类</label>
		      <select name="pid" id="pid2" class="form-control">
		      	<option value="0">请选择标签分类</option>
		      	<volist id="type2" name="type2">
		         <option value="{$type2.id}">{$type2.name}</option>
		        </volist>
		      </select>
		      </div>
		      <div class="form-group col-sm-4" id="sonid2_div" style="display:none;clear:right;margin-left:-30px;">
	          <label for="sonid2">&nbsp;</label>
		      <select name="sonid" id="sonid2" class="form-control"></select>
		      </div>
  			<div class="form-group col-sm-12">
    			<label for="content2">请添加百度风云榜链接</label>
    			<textarea id="content2" name="url" class="form-control" rows="3" placeholder='http://top.baidu.com/buzz?b=26&c=1&fr=topcategory_c1'></textarea>
    			<span class="help-block">这里不支持批量添加哦，每次只能一个百度风云榜的链接。。</span>
  			</div>
		</form>
         </div>
         
         <div class="modal-footer" style="clear:both">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
            <button type="button" id="collect_code" class="btn btn-primary">
               马上采集收录
            </button>
         </div>
      </div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
<script>
$(document).ready(function(){
	//以下为手动添加
	$("#pid").change(function(){
		var pid=$(this).val();
		if(pid!=0){
			var code="";
			$.post("{:U('Tag/getsontype')}",{pid:pid},function(data){
				$("#sonid").empty();
				$.each(data,function(i){
					code+="<option value="+data[i].id+">"+data[i].name+"</option>";
				});
				$("#sonid").append(code);
			});
			$("#sonid_div").css('display','block');
			
		}else{
			$("#sonid_div").css('display','none');
		}
	});
	$("#submit_tag").click(function(){
		if($("#pid").val()==0 || $("#content").val()==""){
			alert('标签分类和内容均不能留空');
			return false;
		}else{
			$("#tag_form").submit();
		}
	});
	
	
	//以下为采集百度风云榜
	$("#pid2").change(function(){
		var pid2=$(this).val();
		if(pid2!=0){
			var code="";
			$.post("{:U('Tag/getsontype')}",{pid:pid2},function(data){
				$("#sonid2").empty();
				$.each(data,function(i){
					code+="<option value="+data[i].id+">"+data[i].name+"</option>";
				});
				$("#sonid2").append(code);
			});
			$("#sonid2_div").css('display','block');
		}else{
			$("#sonid2_div").css('display','none');
		}
	});
	
	$("#collect_code").click(function(){
		if($("#pid2").val()==0 || $("#content2").val()==""){
			alert('标签分类和百度风云榜采集链接均不能留空');
			return false;
		}else{
			$("#collect_form_code").submit();
		}
	});
	$("li.tag").click(function(){
		_this=$(this);
		var v=_this.val();
		if(confirm("您确定要删除该标签吗？")){
			$.get("{:U('Tag/tag_delete')}",{id:v},function(data){
				if(data==1){
					_this.remove();
				}else{
					alert('删除失败，请刷新页面后再重试');
				}
			});	
		}
	});
	
});
$(function () { $("[data-toggle='tooltip']").tooltip(); });
</script>







